package com.tongtong.middleware.blockchain.client.web3j.contract;

import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.datatypes.*;
import org.web3j.abi.datatypes.generated.Uint256;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ERC721Input {
    /**
     * 铸造NFT(需要管理权限用户操作)
     * function mint(address to, uint256 id)
     */
    public static String mint(String to, BigInteger id) {
        Function function = new Function("mint",
                Arrays.asList(new Address(to), new Uint256(id)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
    /**
     * 销毁NFT(需要管理权限用户操作)
     * function burn(uint256 id)
     */
    public static String burn(BigInteger id) {
        Function function = new Function("burn",
                List.of(new Uint256(id)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
    /**
     * 获取授权(需要管理权限用户操作)
     * function approval(address account_)
     */
    public static String approval(String account) {
        Function function = new Function("approval",
                List.of(new Address(account)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
    /**
     * 转移NFT(需要NFT归属用户操作)
     * function safeTransferFrom(address from, address to, uint256 tokenId)
     */
    public static String safeTransferFrom(String from, String to, BigInteger id) {
        Function function = new Function("safeTransferFrom",
                Arrays.asList(new Address(from), new Address(to), new Uint256(id)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
    /**
     * 查询指定用户拥有TokenID的数量
     * function balanceOf(address owner)
     */
    public static String balanceOf(String owner) {
        Function function = new Function("balanceOf",
                List.of(new Address(owner)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
    /**
     * 查询用户是否被指定操作者授权
     * function isApprovedForAll(address owner, address operator)
     */
    public static String isApprovedForAll(String account, String operator) {
        Function function = new Function("isApprovedForAll",
                Arrays.asList(new Address(account), new Address(operator)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
    /**
     * 查询指定TokenID的TokenURI
     * function tokenURI(uint256 tokenId)
     */
    public static String tokenURI(BigInteger tokenId) {
        Function function = new Function("tokenURI",
                List.of(new Uint256(tokenId)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
    /**
     * 查询指定TokenID的拥有者地址
     * function ownerOf(uint256 tokenId)
     */
    public static String ownerOf(BigInteger tokenId) {
        Function function = new Function("ownerOf",
                List.of(new Uint256(tokenId)),
                Collections.singletonList(null));
        return FunctionEncoder.encode(function);
    }
}
